//
//  ViewController.swift
//  关键帧动画转盘抽奖
//
//  Created by app on 2017/4/13.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var imageView:UIImageView!
    var index:Int = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.white
        imageView = UIImageView()
        imageView.frame = UIScreen.main.bounds
        imageView.image = UIImage(named: "turntable")
        
        view.addSubview(imageView)
        
        animationCircle()
    }

    
    func animationCircle() {
        UIView.animateKeyframes(withDuration: 0.2, delay: 0, options: UIViewKeyframeAnimationOptions(), animations: { 
            UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/4, animations: { 
                self.index += 1
                let angle = CGFloat(M_PI_2) * CGFloat(self.index)
                self.imageView.transform = CGAffineTransform(rotationAngle: angle)
            })
            
        }) { (finsh) in
            self.animationCircle()
        }
    }

}

